package org.hxzon.configdesigner.web.pages;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.hxzon.configdesigner.core.CfgValue;
import org.hxzon.configdesigner.web.pages.base.PageBase;
import org.hxzon.configdesigner.web.util.CfgUtil;

public class View extends PageBase {

    private int indexCode;
    @Property
    private CfgValue cfg;

    Object withInit(int indexCode) {
        this.indexCode = indexCode;
        return this;
    }

    @OnEvent(value = EventConstants.ACTIVATE)
    void init(int indexCode) {
        withInit(indexCode);
    }

    @SetupRender
    void setup() {
        cfg = CfgUtil.findCfg(indexCode);
    }

    @OnEvent(value = EventConstants.PASSIVATE)
    Object toPassivate() {
        return indexCode;
    }
}
